package com.zw.a.basic.a10.demo04_enhancefor;

import com.itheima.demo01_collection.Student;

import java.util.ArrayList;
import java.util.List;

//案例: 演示增强for遍历 List集合, 存储自定义类型的数据.
public class Demo03 {
    public static void main(String[] args) {
        //1.定义学生类, 属性为姓名和年龄.
        //2.创建List集合, 用来存储学生对象.
        List<Student> list = new ArrayList<>();
        //3.往集合中添加3个学生的信息.
        /*Student s1 = new Student("刘亦菲", 33);
        list.add(s1);*/
        list.add(new Student("刘亦菲", 33));
        list.add(new Student("赵丽颖", 31));
        list.add(new Student("高圆圆", 35));

        //4.通过增强for遍历上述的List集合.
        for (Student s : list) {
            System.out.println(s);
        }
    }
}
